package com.campus.client.controller;


import com.campus.client.net.ClientConnector;
import com.campus.common.message.StudentAccountManagementResponse;
import com.campus.common.vo.Student;

import javax.swing.*;
import java.io.IOException;
import java.util.List;

public class StudentAccountManagementController {
    private ClientConnector connector;

    public StudentAccountManagementController(ClientConnector connector) {
        this.connector = connector;
    }

    public List<Student> getStudents() throws ClassNotFoundException, IOException {
        StudentAccountManagementResponse resp = connector.listStudents();
        return resp.getStudents();
    }

    public boolean addStudent(Student student) throws ClassNotFoundException, IOException {

        StudentAccountManagementResponse resp = connector.addStudent(student);
        return resp.isSuccess();
    }
    public boolean deleteStudent(String id) throws ClassNotFoundException, IOException {
        StudentAccountManagementResponse resp = connector.deleteStudent(id);
        return resp.isSuccess();
    }
    public List<Student> searchStudentsById(String id) throws ClassNotFoundException, IOException {
        StudentAccountManagementResponse resp = connector.searchStudentsById(id);
        return resp.getStudents();
    }

    public List<Student> searchStudentsByName(String name) throws ClassNotFoundException, IOException {
        StudentAccountManagementResponse resp = connector.searchStudentsByName(name);
        return resp.getStudents();
    }

    public List<Student> searchStudents(String title, String author) throws ClassNotFoundException, IOException {
        StudentAccountManagementResponse resp = connector.searchStudents(title, author);
        return resp.getStudents();
    }
    public boolean updateStudent(Student student) throws ClassNotFoundException, IOException {
        StudentAccountManagementResponse resp = connector.updateStudents(student);
        return resp.isSuccess();
    }

    // 可选：结束会话时关闭连接
    public void closeConnection() throws IOException {
        connector.close();
    }
}
